namespace DotNetNuke.Common.Lists
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;

    public class ListInfoCollection : CollectionBase
    {
        private Hashtable mKeyIndexLookup = new Hashtable();

        public void Add(string key, object value)
        {
            try
            {
                int index = base.List.Add(RuntimeHelpers.GetObjectValue(value));
                this.mKeyIndexLookup.Add(key.ToLower(), index);
            }
            catch (Exception exception1)
            {
                
                Exception ex = exception1;
                
            }
        }

        internal void Clear()
        {
            this.mKeyIndexLookup.Clear();
            base.Clear();
        }

        public ArrayList GetChild(string ParentKey)
        {
            IEnumerator refObjectHelperL0=null;
            ArrayList childList = new ArrayList();
            try
            {
                refObjectHelperL0 = this.List.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    object child = RuntimeHelpers.GetObjectValue(refObjectHelperL0.Current);
                    if (((ListInfo) child).Key.IndexOf(ParentKey.ToLower()) > -1)
                    {
                        childList.Add(RuntimeHelpers.GetObjectValue(child));
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            return childList;
        }

        public ListInfo GetChildren(string ParentName)
        {
            return (ListInfo) this.Item(ParentName);
        }

        public object Item(int index)
        {
            object Item;
            try
            {
                Item = RuntimeHelpers.GetObjectValue(base.List[index]);
            }
            catch (Exception exception1)
            {
                
                Exception Exc = exception1;
                Item = null;
                
                return Item;
                
            }
            return Item;
        }

        public object Item(string key)
        {
            try
            {
                if (this.mKeyIndexLookup[key.ToLower()] == null)
                {
                    return null;
                }
            }
            catch (Exception exception1)
            {
                
                Exception ex = exception1;
                object Item = null;
                
                return Item;
                
            }
            int index = Conversions.ToInteger(this.mKeyIndexLookup[key.ToLower()]);
            return RuntimeHelpers.GetObjectValue(base.List[index]);
        }

        public object Item(string key, bool Cache)
        {
            object obj = null;
            bool itemExists = false;
            try
            {
                if (this.mKeyIndexLookup[key.ToLower()] != null)
                {
                    itemExists = true;
                }
            }
            catch (Exception exception1)
            {
                
                Exception ex = exception1;
                
            }
            if (!itemExists)
            {
                ListController ctlLists = new ListController();
                string listName = key.Substring(key.IndexOf(":") + 1);
                string parentKey = key.Replace(listName, "").TrimEnd(new char[] { ':' });
                ListInfo listInfo = ctlLists.GetListInfo(listName, parentKey);
                if (Cache)
                {
                    this.Add(listInfo.Key, listInfo);
                    return listInfo;
                }
                return obj;
            }
            int index = Conversions.ToInteger(this.mKeyIndexLookup[key.ToLower()]);
            return RuntimeHelpers.GetObjectValue(base.List[index]);
        }
    }
}

